package com.xuyuan.interview.scene.coupon;

import com.xuyuan.interview.scene.api.CouponCondition;
import com.xuyuan.interview.scene.entity.Order;

import java.math.BigDecimal;

public class DiscountCoupon extends CouponCondition {
    private BigDecimal discountRate;

    @Override
    public String getCouponName() {
        return this.getClass().getSimpleName();
    }

    @Override
    public Order applyDiscount(Order order) {
        order.setTotalPrice(order.getTotalPrice().multiply(this.discountRate));
        return order;
    }

    @Override
    public BigDecimal findPriority(Order order) {
        return this.applyDiscount(order).getTotalPrice();
    }
}
